//index.js
import api from '../../../utils/api.js'
//获取应用实例
var app = getApp();
Page({
  data: {
phone:'',
content:''
  },
  contentChange:function(e){
    var content = e.detail.value
    console.log('content',content)
    this.setData({
      content: content
    })
  },
  phoneChange: function (e) {
    var phone = e.detail.value
    console.log('phone', phone)
    this.setData({
      phone: phone
    })
  },
  formsubmit: function () {
    var that = this
    var phone = that.data.phone
    var content = that.data.content
    // 内容为空判断
    if (content == null || content == "") {
      wx.showModal({
        content: "反馈内容不能为空",
        confirmText: "确定",
        showCancel: false,
      })
      return;
    }
    if (phone == '') {
      wx.showModal({
        content: "请填写手机号码",
        confirmText: "确定",
        showCancel: false,
      })
      return;
    }
    if (!(/^1[34578]\d{9}$/.test(phone))) {
      wx.showModal({
        content: "请填写正确的手机号码",
        confirmText: "确定",
        showCancel: false,
      })
      return;
    }
    api.addFeedback({
      data: {
        phone: phone,
        content: content,
        userId:app.globalData.userid,
      },
      success: function (res) {
        console.log('反馈', res)
        wx.switchTab({
          url: '../index/index'
        })
      }
    })
  },
  onShareAppMessage: function () {
    return {
      path: '/pages/index/index',
    }
  },
})